package com.jcy_lyh.enjoy_all;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class Second2Activity extends AppCompatActivity {
    private EditText etvalue1;
    private EditText etvalue2;
    private EditText etvalue3;
    private EditText etvalue4;
    private EditText etvalue5;
    private EditText budget;
    private TextView textView;
    private double value1, value2, value3, value4, value5, value6;
    private double result;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second2);

        etvalue1 = (EditText) findViewById(R.id.editText2);
        etvalue2 = (EditText) findViewById(R.id.editText4);
        etvalue3 = (EditText) findViewById(R.id.editText6);
        etvalue4 = (EditText) findViewById(R.id.editText8);
        etvalue5 = (EditText) findViewById(R.id.editText10);
        textView = (TextView) findViewById(R.id.textView3);
        budget = (EditText) findViewById(R.id.editText12);


        Button sum = findViewById(R.id.button5);
        sum.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                value1 = Double.parseDouble(etvalue1.getText().toString());
                value2 = Double.parseDouble(etvalue2.getText().toString());
                value3 = Double.parseDouble(etvalue3.getText().toString());
                value4 = Double.parseDouble(etvalue4.getText().toString());
                value5 = Double.parseDouble(etvalue5.getText().toString());
                value6 = Double.parseDouble(budget.getText().toString());
                result = value1+ value2 + value3 + value4 + value5;
                textView.setText("" + result + "");

                if(result > value6) {
                    Toast.makeText(Second2Activity.this, "花销已超出预算，请注意开支！(；′⌒`)", Toast.LENGTH_LONG).show();
                }
                else {
                    Toast.makeText(Second2Activity.this, "花销合理有余，请继续保持哦。(*￣︶￣)", Toast.LENGTH_LONG).show();
                }
            }
        });
    }
}
